use crate::core::model::{Board, Component, ComponentParameters, Toolpath};
use crate::error::ProcessingError;
use crate::processing::strategies::machiningStrategy::MachiningStrategy;

pub struct SlotStrategy;

impl MachiningStrategy for SlotStrategy {
    fn generate_toolpath(&self, component: &Component, board: &Board) ->Result<Vec<Toolpath>, ProcessingError>{
        // 实现槽加工逻辑
        println!("槽加工路径");
        let params = match &component.parameters {
            ComponentParameters::Slot(p) => p,
            _ =>return Err(ProcessingError::ParameterError(
                format!("组件 {} 需要槽参数", component.id)
            )),
        };

        // 直接访问强类型参数
        let width = params.width;
        let length = params.length;
        let depth = params.depth.unwrap_or(board.thickness);
        let corner_radius = params.corner_radius.unwrap_or(0.0);

        // 选择刀具 - 考虑拐角半径
        let tool = if corner_radius > 0.0 {
            tools.select_tool(ToolType::BallNose, width)?
        } else {
            tools.select_tool(ToolType::EndMill, width)?
        };

        // 计算槽的几何形状
        let path = calculate_slot_path(
            component.position,
            length,
            width,
            component.rotation,
            corner_radius
        );

        // 生成加工操作
        let operations = generate_slot_operations(&path, depth, tool.diameter);

        Ok(vec![Toolpath {
            tool,
            operations,
            metadata: HashMap::new(),
        }])
        
        
        
    }
}